function doSearch(){
    $("#dg").datagrid("load",{
        customerNmae:$("#customerNmae").val()
    });
}
function editOrder(){
    var row = $('#dg').datagrid('getSelected');
    if (row){
        $('#dlg-update').dialog('open').dialog('center').dialog('setTitle','修改订单信息');
        $('#fm-update').form('load',row);
        url = '/Lease/editOrder.json?id='+row.id;
    }
}
$(function(){
    $("#dg").datagrid({
        onDblClickRow:function(index,row){
            location.href="/Lease/toViewOrder.htm?id="+row.id;
        }
    });
    $('#customerName').combogrid({
            panelWidth:450,
            idField:'id',
            textField:'name',
            url:'/Lease/customer.json?page=0&rows=0',
            columns:[[
                {field:'id',title:'ID',width:60},
                {field:'name',title:'姓名',width:100},
                {field:'phone',title:'电话',width:120},
                {field:'address',title:'地址',width:100},
                {field:'remark',title:'备注',width:100}
            ]],
           mode:'remote'
        });
})
var url;
function newOrder(){
    $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增客户信息');
    $('#fm').form('clear');
    url = '/Lease/saveOrder.json';
}
function saveOrder(){
    $('#fm').form('submit',{
        url: url,
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            var result = eval('('+result+')');
            if (result.errorMsg){
                $.messager.show({
                    title: '错误',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}
function updateOrder(){
$('#fm-update').form('submit',{
        url: url,
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            var result = eval('('+result+')');
            if (result.errorMsg){
                $.messager.alert("失败",result.errorMsg);
            } else {
                $('#dlg-update').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}